package com.clas.liu.myapplication.view.activity.impl;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.ImageView;

import com.clas.liu.myapplication.R;
import com.clas.liu.myapplication.presenter.impl.BasePresenter;
import com.clas.liu.myapplication.view.util.SaveUtil;
import com.squareup.picasso.Picasso;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by liu on 2019/5/22.
 */

public class StartActivity extends BaseActivity {

    private ImageView imageView;
    private int[] pic = {R.mipmap.start1,R.mipmap.start2,R.mipmap.start3,R.mipmap.start4,
            R.mipmap.start5,R.mipmap.start6,R.mipmap.start7};
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start_layout);
        findView();
        init();
    }

    private void init() {
        setStatusBarTransparent();
        final Intent intent;
        Picasso.with(this).load(pic[(((int)(1+Math.random()*10))%6)]).into(imageView);
        if (SaveUtil.getFromLocal(getApplicationContext(),"user")!=null &&
                SaveUtil.getLoginStatus(getApplicationContext())) {
            intent = new Intent(this,MainActivity.class);
        }else {
            intent = new Intent(this,LoginActivity.class);
        }
        Timer timer=new Timer();
        TimerTask timerTask=new TimerTask() {
            @Override
            public void run() {
               startActivity(intent);
               StartActivity.this.finish();
            }
        };
        timer.schedule(timerTask,1300);


    }

    private void findView() {
        imageView = findViewById(R.id.start_iv);
    }

    @Override
    protected BasePresenter getPresenter() {
        return null;
    }
}
